﻿using System;
using Simp.CodeModel;
using System.Windows;
using System.Collections.Generic;
using System.Windows.Shapes;
using System.Windows.Controls;

namespace Simp.GraphModel
{
	/// <summary>Encapsulate a line function.</summary>
	public class LineFunction : IElementProducerFunction
	{
		private static readonly string[] PARAMETER_NAMES = new[] { "p1", "p2" };

		#region IFunction Members
		string IFunction.FunctionName
		{
			get { return "Line"; }
		}

		string[] IFunction.ParameterNames
		{
			get { return PARAMETER_NAMES; }
		}

		IFunctionParameterBinding[] IFunction.DefaultParameterValues
		{
			get { return FunctionHelper.EmptyBindings; }
		}

		IFunction IFunction.Simplify(SimplificationMode simplificationMode, params IFunction[] parameters)
		{
			return null;
		}

		IFunction IFunction.AcceptVisitor(IFunctionVisitor visitor)
		{
			return null;
		}
		#endregion

		#region IElementProducer Members
		UIElement IElementProducerFunction.Produce(params IFunction[] parameters)
		{
			FunctionHelper.ValidateParameters(this, parameters);

			IFunction p1 = parameters[0];
			IFunction p2 = parameters[1];
			double x1, y1, x2, y2;

			if (PointFunction.TryGetCartesian(p1, out x1, out y1))
			{
				if (PointFunction.TryGetCartesian(p2, out x2, out y2))
				{
					Line line =
						new Line { X1 = x1, Y1 = y1, X2 = x2, Y2 = y2, Stroke = GraphicHelper.DefaultStroke };

					return line;
				}
			}

			return null;
		}
		#endregion
	}
}